import { defineStore } from 'pinia'

export const useMeasureStore = defineStore('measure', {
  state: () => ({
    measureType: null,
    isDrawing: false,
    hasError: false,
    errorMsg: '',
    measureResults: [],
    currentFeature: null,
    measureLayer: null,
    measureSource: null,
    measureOverlay: null,
    measureTooltip: null,
    measureTooltipElement: null,
    measureTooltipOverlay: null
  }),

  getters: {
    isMeasuring: (state) => state.isDrawing,
    currentMeasureType: (state) => state.measureType,
    hasMeasureError: (state) => state.hasError,
    getMeasureResults: (state) => state.measureResults
  },

  actions: {
    setMeasureType(type) {
      this.measureType = type
    },

    setDrawing(status) {
      this.isDrawing = status
    },

    setError(hasError, message = '') {
      this.hasError = hasError
      this.errorMsg = message
    },

    addMeasureResult(result) {
      this.measureResults.push(result)
    },

    clearMeasureResults() {
      this.measureResults = []
    },

    setCurrentFeature(feature) {
      this.currentFeature = feature
    },

    setMeasureLayer(layer) {
      this.measureLayer = layer
    },

    setMeasureSource(source) {
      this.measureSource = source
    },

    setMeasureOverlay(overlay) {
      this.measureOverlay = overlay
    },

    setMeasureTooltip(tooltip) {
      this.measureTooltip = tooltip
    },

    setMeasureTooltipElement(element) {
      this.measureTooltipElement = element
    },

    setMeasureTooltipOverlay(overlay) {
      this.measureTooltipOverlay = overlay
    },

    resetMeasureState() {
      this.measureType = null
      this.isDrawing = false
      this.hasError = false
      this.errorMsg = ''
      this.currentFeature = null
    }
  }
}) 